package com.second.app.quickfind;

public class QuickFindDemo {
    public static void main(String[] args) {
        int[] arr = {-1, 0, 3, 5, 9, 12, 22, 30};
        int val = quickFind(arr, 12);
        System.out.println(val);
    }

    public static int quickFind(int[] arr, int target) {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] == target) {
                return mid;
            } else if (arr[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return -1;
    }
}
